﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using StoragePeriod.Model.RawDict;
using StoragePeriod.BLL.RawDict;

namespace StoragePeriod.Web.Nutritionknowledge
{
    public partial class StorageintroEdit : System.Web.UI.Page
    {
        T_IntroduceStorage tIntroduceStorage = new T_IntroduceStorage();//贮存知识

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["RawID"] != null)
                {
                    LoadData();
                }
            }
        }

        //加载数据
        private void LoadData()
        {
            int RawID = int.Parse(Request.QueryString["RawID"].ToString());
            E_IntroduceStorage eIntroduceStorage = tIntroduceStorage.GetModelList("RawID=" + RawID).FirstOrDefault();

            if (eIntroduceStorage != null)
            {
                this.FCK_RawContent.Value = eIntroduceStorage.RawContent;//原料简介
                this.FCK_StoragePrompt.Value = eIntroduceStorage.StoragePrompt;//贮存提示
            }
            else
            {
                this.FCK_RawContent.Value = "";
                this.FCK_StoragePrompt.Value = "";
            }
        }

        protected void btn_save_Click(object sender, EventArgs e)
        {
            int RawID = int.Parse(Request.QueryString["RawID"].ToString());
            bool IsAdd = false;

            E_IntroduceStorage eIntroduceStorage = tIntroduceStorage.GetModelList("RawID=" + RawID).FirstOrDefault();
            if (eIntroduceStorage == null)
            {
                eIntroduceStorage = new E_IntroduceStorage();
                IsAdd = true;
            }
            eIntroduceStorage.RawID = RawID;
            eIntroduceStorage.RawContent = this.FCK_RawContent.Value;
            eIntroduceStorage.StoragePrompt = this.FCK_StoragePrompt.Value;
            eIntroduceStorage.AddTime = DateTime.Now;

            if (IsAdd)
            {
                tIntroduceStorage.Add(eIntroduceStorage);
            }
            else
            {
                tIntroduceStorage.Update(eIntroduceStorage);
            }
            ScriptManager.RegisterStartupScript(this, Page.GetType(), "", "<script type='text/javascript'>alert('保存成功！');</script>", false);
        }
    }
}